/*
 * ConnectDialogPostgresql.java
 *
 * Created on 27 de septiembre de 2006, 7:53
 */

package es.atareao.queensboro.gui;

import java.awt.Frame;
import es.atareao.queensboro.db.ConectorPostgresql;

/**
 *
 * @author  Protactino
 */
public class ConnectDialogPostgresql extends javax.swing.JDialog {
    //
    //********************************CONSTANTES********************************
    //
    /** A return status code - returned if Cancel button has been pressed */
    public static final int RET_CANCEL = 0;
    /** A return status code - returned if OK button has been pressed */
    public static final int RET_OK = 1;
    //
    //******************************CONSTRUCTORES*******************************
    //
    /** Creates new form MarcoDocumento */
    public ConnectDialogPostgresql(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }
    public ConnectDialogPostgresql(){
        super(new Frame(),true);
        initComponents();
        this.setSize(400,260);
        this.setLocationRelativeTo(null);
    }
    public ConnectDialogPostgresql(String serverName,String port,String databaseName,String userName){
        super(new Frame(),true);
        initComponents();
        this.setSize(400,260);
        this.setLocationRelativeTo(null);
        this.jServidor.setText(serverName);
        this.jPuerto.setText(port);
        this.jDatabase.setText(databaseName);
        this.jUsuario.setText(userName);
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jDatabase = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jServidor = new javax.swing.JTextField();
        jPuerto = new javax.swing.JTextField();
        jUsuario = new javax.swing.JTextField();
        jPassword = new javax.swing.JPasswordField();
        jAceptar = new javax.swing.JButton();
        jCancelar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Conexión");
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel3.setText("Database:");
        jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 70, 60, 20));
        jPanel1.add(jDatabase, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 70, 160, -1));

        jLabel4.setText("Servidor:");
        jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 60, 20));

        jLabel5.setText("Puerto:");
        jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 40, 50, 20));

        jLabel6.setText("Usuario:");
        jPanel1.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 100, 50, 20));

        jLabel7.setText("Password:");
        jPanel1.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 130, 60, 20));
        jPanel1.add(jServidor, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 10, 160, -1));
        jPanel1.add(jPuerto, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 40, 160, -1));

        jUsuario.setText("postgres");
        jPanel1.add(jUsuario, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 100, 160, -1));
        jPanel1.add(jPassword, new org.netbeans.lib.awtextra.AbsoluteConstraints(80, 130, 160, 20));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 10, 250, 160));

        jAceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/protactino/queensboro/img/button_ok.png"))); // NOI18N
        jAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jAceptarActionPerformed(evt);
            }
        });
        getContentPane().add(jAceptar, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 180, 40, 40));

        jCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/protactino/queensboro/img/button_cancel.png"))); // NOI18N
        jCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCancelarActionPerformed(evt);
            }
        });
        getContentPane().add(jCancelar, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 180, 40, 40));

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/protactino/queensboro/img/password.png"))); // NOI18N
        jLabel1.setText("jLabel1");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 120, 160));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCancelarActionPerformed
// TODO add your handling code here:
        this.setConector(null);
        this.setReturnStatus(RET_CANCEL);
        this.dispose();        
    }//GEN-LAST:event_jCancelarActionPerformed

    private void jAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jAceptarActionPerformed
// TODO add your handling code here:
        String server=jServidor.getText();
        String port=jPuerto.getText();
        String databaseName=jDatabase.getText();
        String user=jUsuario.getText();
        char[] password=jPassword.getPassword();
        this.setConector(new ConectorPostgresql(server,port,databaseName,user,password));
        this.setReturnStatus(RET_OK);
        this.dispose();
    }//GEN-LAST:event_jAceptarActionPerformed
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jAceptar;
    private javax.swing.JButton jCancelar;
    private javax.swing.JTextField jDatabase;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPasswordField jPassword;
    private javax.swing.JTextField jPuerto;
    private javax.swing.JTextField jServidor;
    private javax.swing.JTextField jUsuario;
    // End of variables declaration//GEN-END:variables
    //
    // *********************************CAMPOS*********************************
    //
    private int _returnStatus = RET_CANCEL;
    private ConectorPostgresql _conector;

    public ConectorPostgresql getConector() {
        return _conector;
    }

    public void setConector(ConectorPostgresql conector) {
        this._conector = conector;
    }

    public int getReturnStatus() {
        return _returnStatus;
    }

    public void setReturnStatus(int returnStatus) {
        this._returnStatus = returnStatus;
    }
}
